/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIBranch.java
 *
 * Created on Oct 14, 2011, 12:44:39 PM
 */
package gui;

import Config.Localization;
import bl.BLLoanContact;
import bl.BLLoanType;
import entities.LoanContact;
import entities.LoanType;
import entities.User;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import java.sql.Date;

/**
 *
 * @author Bich Tran Van
 */
public class GUILoanContact extends javax.swing.JPanel {

    private ArrayList<LoanContact> loanContacts = null;
    private BLLoanContact blLoanContact = null;
    private LoanContact loanContact = null;
    private User user;

    /** Creates new form GUIBranch */
    public GUILoanContact(User user) {
        this.user = user;
        initComponents();
        authorization();
        loanContacts = new ArrayList<LoanContact>();
        blLoanContact = new BLLoanContact();
        loadListLoanType();
        refreshData();
        search();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlControl = new javax.swing.JPanel();
        btnList = new javax.swing.JButton();
        txtSearch = new javax.swing.JTextField();
        lblFrom = new javax.swing.JLabel();
        txtFromAmount = new javax.swing.JTextField();
        txtFromDate = new com.toedter.calendar.JDateChooser();
        lblTo = new javax.swing.JLabel();
        txtToAmount = new javax.swing.JTextField();
        txtToDate = new com.toedter.calendar.JDateChooser();
        cboSearch = new javax.swing.JComboBox();
        btnSearch = new javax.swing.JButton();
        cboView = new javax.swing.JComboBox();
        pnlTop = new javax.swing.JPanel();
        pnlCustomerDetails = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lblCustomerID = new javax.swing.JLabel();
        lblFullName = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblAddress = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lblPhoneNumber = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        lblOrgazination = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        lblGrossSalary = new javax.swing.JLabel();
        pnlLoanDetails = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        lblLoanID = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        cboLoanType = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        txtAmount = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        btnApproved = new javax.swing.JButton();
        btnDeline = new javax.swing.JButton();
        txtDate = new com.toedter.calendar.JDateChooser();
        jPanel1 = new javax.swing.JPanel();
        btnKeepTrack = new javax.swing.JButton();
        pnlBottom = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblList = new javax.swing.JTable();

        setAlignmentX(0.0F);
        setAlignmentY(0.0F);
        setAutoscrolls(true);
        setMinimumSize(new java.awt.Dimension(826, 519));
        setPreferredSize(new java.awt.Dimension(826, 519));

        btnList.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/list1.png"))); // NOI18N
        btnList.setText("List");
        btnList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnListActionPerformed(evt);
            }
        });
        pnlControl.add(btnList);

        txtSearch.setMinimumSize(new java.awt.Dimension(100, 20));
        txtSearch.setPreferredSize(new java.awt.Dimension(120, 25));
        pnlControl.add(txtSearch);

        lblFrom.setFont(new java.awt.Font("Tahoma", 0, 15));
        lblFrom.setText("From");
        pnlControl.add(lblFrom);

        txtFromAmount.setMinimumSize(new java.awt.Dimension(100, 20));
        txtFromAmount.setPreferredSize(new java.awt.Dimension(120, 25));
        txtFromAmount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFromAmountActionPerformed(evt);
            }
        });
        pnlControl.add(txtFromAmount);

        txtFromDate.setDateFormatString("dd/MM/yyyy");
        txtFromDate.setPreferredSize(new java.awt.Dimension(120, 25));
        pnlControl.add(txtFromDate);

        lblTo.setFont(new java.awt.Font("Tahoma", 0, 15));
        lblTo.setText("To");
        pnlControl.add(lblTo);

        txtToAmount.setMinimumSize(new java.awt.Dimension(100, 20));
        txtToAmount.setPreferredSize(new java.awt.Dimension(120, 25));
        txtToAmount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtToAmountActionPerformed(evt);
            }
        });
        pnlControl.add(txtToAmount);

        txtToDate.setDateFormatString("dd/MM/yyyy");
        txtToDate.setPreferredSize(new java.awt.Dimension(120, 25));
        pnlControl.add(txtToDate);

        cboSearch.setFont(new java.awt.Font("Tahoma", 0, 12));
        cboSearch.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Loan ID", "Customer ID", "Amount", "Date Of Loan" }));
        cboSearch.setAlignmentX(0.0F);
        cboSearch.setPreferredSize(new java.awt.Dimension(120, 25));
        cboSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboSearchActionPerformed(evt);
            }
        });
        pnlControl.add(cboSearch);

        btnSearch.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/xmag.png"))); // NOI18N
        btnSearch.setText("Search");
        btnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchActionPerformed(evt);
            }
        });
        pnlControl.add(btnSearch);

        cboView.setFont(new java.awt.Font("Tahoma", 0, 12));
        cboView.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select View Loan", "Home Loan", "Vehicle Loan", "Personal Loan", "Educational", "Waiting", "Approved", "Cancel" }));
        cboView.setAlignmentX(0.0F);
        cboView.setMinimumSize(new java.awt.Dimension(170, 19));
        cboView.setPreferredSize(new java.awt.Dimension(120, 25));
        cboView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboViewActionPerformed(evt);
            }
        });
        pnlControl.add(cboView);

        pnlTop.setAlignmentX(0.0F);
        pnlTop.setAlignmentY(0.0F);
        pnlTop.setAutoscrolls(true);
        pnlTop.setLayout(new java.awt.BorderLayout());

        pnlCustomerDetails.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Customer Details", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
        pnlCustomerDetails.setAlignmentX(0.0F);
        pnlCustomerDetails.setAlignmentY(0.0F);

        jLabel1.setText("CustomerID");

        lblCustomerID.setText("id");

        lblFullName.setText("Full Name");

        jLabel4.setText("Full Name");

        jLabel5.setText("Address");

        lblAddress.setText("Address");

        jLabel7.setText("Phone number");

        lblPhoneNumber.setText("Address");

        jLabel9.setText("Email");

        lblEmail.setText("Email");

        jLabel11.setText("Organzination");

        lblOrgazination.setText("Email");

        jLabel13.setText("Gross Salary");

        lblGrossSalary.setText("Email");

        javax.swing.GroupLayout pnlCustomerDetailsLayout = new javax.swing.GroupLayout(pnlCustomerDetails);
        pnlCustomerDetails.setLayout(pnlCustomerDetailsLayout);
        pnlCustomerDetailsLayout.setHorizontalGroup(
            pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlCustomerDetailsLayout.createSequentialGroup()
                .addContainerGap(78, Short.MAX_VALUE)
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblAddress, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblPhoneNumber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblOrgazination, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblFullName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblCustomerID, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
                    .addComponent(lblGrossSalary, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(68, 68, 68))
        );
        pnlCustomerDetailsLayout.setVerticalGroup(
            pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCustomerDetailsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblCustomerID))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lblFullName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lblAddress))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(lblPhoneNumber))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(lblEmail))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(lblOrgazination))
                .addGap(18, 18, 18)
                .addGroup(pnlCustomerDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(lblGrossSalary))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        pnlTop.add(pnlCustomerDetails, java.awt.BorderLayout.WEST);

        pnlLoanDetails.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Loan Details", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jLabel15.setText("LoanID");

        lblLoanID.setText("                                             ");

        jLabel17.setText("Loan Type");

        cboLoanType.setEnabled(false);

        jLabel18.setText("Amount");

        txtAmount.setEnabled(false);

        jLabel19.setText("Date");

        btnApproved.setText("Accept");
        btnApproved.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnApprovedActionPerformed(evt);
            }
        });

        btnDeline.setText("Deline");
        btnDeline.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelineActionPerformed(evt);
            }
        });

        txtDate.setDateFormatString("MM/dd/yyyy");
        txtDate.setEnabled(false);

        btnKeepTrack.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnKeepTrack.setText("Keeptrack");
        btnKeepTrack.setMaximumSize(new java.awt.Dimension(89, 25));
        btnKeepTrack.setMinimumSize(new java.awt.Dimension(89, 25));
        btnKeepTrack.setPreferredSize(new java.awt.Dimension(89, 25));
        btnKeepTrack.setRolloverEnabled(false);
        btnKeepTrack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKeepTrackActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlLoanDetailsLayout = new javax.swing.GroupLayout(pnlLoanDetails);
        pnlLoanDetails.setLayout(pnlLoanDetailsLayout);
        pnlLoanDetailsLayout.setHorizontalGroup(
            pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlLoanDetailsLayout.createSequentialGroup()
                .addGap(52, 52, 52)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 191, Short.MAX_VALUE)
                .addComponent(btnKeepTrack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(61, 61, 61))
            .addGroup(pnlLoanDetailsLayout.createSequentialGroup()
                .addGap(81, 81, 81)
                .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel17))
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlLoanDetailsLayout.createSequentialGroup()
                        .addComponent(btnApproved)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDeline))
                    .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtDate, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lblLoanID, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtAmount, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                        .addComponent(cboLoanType, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(126, Short.MAX_VALUE))
        );
        pnlLoanDetailsLayout.setVerticalGroup(
            pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlLoanDetailsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblLoanID)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(cboLoanType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel18)
                    .addComponent(txtAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addComponent(txtDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnApproved)
                    .addComponent(btnDeline))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlLoanDetailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnKeepTrack, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pnlTop.add(pnlLoanDetails, java.awt.BorderLayout.CENTER);

        pnlBottom.setAutoscrolls(true);

        tblList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        tblList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblListMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(tblList);

        javax.swing.GroupLayout pnlBottomLayout = new javax.swing.GroupLayout(pnlBottom);
        pnlBottom.setLayout(pnlBottomLayout);
        pnlBottomLayout.setHorizontalGroup(
            pnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBottomLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 814, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnlBottomLayout.setVerticalGroup(
            pnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBottomLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlTop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(pnlControl, javax.swing.GroupLayout.PREFERRED_SIZE, 814, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(pnlBottom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pnlTop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(pnlControl, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlBottom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(80, 80, 80))
        );
    }// </editor-fold>//GEN-END:initComponents

    public void authorization() {
        if (user.getUserType().getTypeId() == 1) {
            btnApproved.setVisible(false);
            btnDeline.setVisible(false);
        }
        if (user.getUserType().getTypeId() == 2) {
           
        }
        if (user.getUserType().getTypeId() == 3) {
            btnApproved.setVisible(false);
            btnDeline.setVisible(false);
        }
    }

    public void refreshData() {
        try {
            this.loanContacts = blLoanContact.getAll(user);
        } catch (Exception e) {
        }
        loadModel(loanContacts);
        lblCustomerID.setText("");
        lblFullName.setText("");
        lblAddress.setText("");
        lblEmail.setText("");
        lblGrossSalary.setText("");
        lblPhoneNumber.setText("");
        lblOrgazination.setText("");
        lblLoanID.setText("");
        cboLoanType.setSelectedIndex(0);
        txtAmount.setText("");
        txtDate.setDate(null);
        btnDeline.setEnabled(false);
        btnKeepTrack.setEnabled(false);
        btnApproved.setEnabled(false);
        
    }

    public void search() {
        txtSearch.setVisible(true);
        txtFromAmount.setVisible(false);
        txtToAmount.setVisible(false);
        txtFromDate.setVisible(false);
        txtToDate.setVisible(false);
        lblFrom.setVisible(false);
        lblTo.setVisible(false);
    }

    public void loadModel(ArrayList<LoanContact> loanContacts) {
        DefaultTableModel mode = new DefaultTableModel();
        mode.addColumn("LoanID");
        mode.addColumn("CustomerName");
        mode.addColumn("Branch Name");
        mode.addColumn("Type Of Loan");
        mode.addColumn("Amount");
        mode.addColumn("Period");
        mode.addColumn("Date Of Loan");
        mode.addColumn("Approved");

        mode.setRowCount(loanContacts.size());
        int i = 0;
        for (LoanContact n : loanContacts) {
            mode.setValueAt(n.getLoanId(), i, 0);
            mode.setValueAt(n.getCustomer().getFullname(), i, 1);
            mode.setValueAt(n.getUser().getBranchId().getBranchName(), i, 2);
            mode.setValueAt(n.getLoantype().getTypeOfLoan(), i, 3);
            mode.setValueAt(n.getAmount(), i, 4);
            mode.setValueAt(n.getPeriod(), i, 5);
            mode.setValueAt(n.getDateStart(), i, 6);
            if (n.isIsAccepted() == 2) {
                mode.setValueAt("Waiting", i, 7);
            }
            if (n.isIsAccepted() == 1) {
                mode.setValueAt("Accepted", i, 7);
            }
            if (n.isIsAccepted() == 0) {
                mode.setValueAt("Cancel", i, 7);
            }
            i++;
        }
        this.tblList.setModel(mode);
    }

    public void loadListLoanType() {
        try {
            ArrayList<LoanType> loantype = new ArrayList<LoanType>();
            BLLoanType blLoanType = new BLLoanType();
            loantype = blLoanType.getAll();
            for (int i = 0; i < loantype.size(); i++) {
                cboLoanType.addItem(loantype.get(i).getTypeOfLoan());
            }


        } catch (Exception ex) {
            Logger.getLogger(GUILoanContact.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
private void cboSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboSearchActionPerformed
// TODO add your handling code here:
    int select = cboSearch.getSelectedIndex();
    if (select == 0 || select == 1) {
        search();
    }

    if (select == 2) {
        txtSearch.setVisible(false);
        txtFromAmount.setVisible(true);
        txtToAmount.setVisible(true);
        txtFromDate.setVisible(false);
        txtToDate.setVisible(false);
        lblFrom.setVisible(true);
        lblTo.setVisible(true);
    }

    if (select == 3) {
        txtSearch.setVisible(false);
        txtFromAmount.setVisible(false);
        txtToAmount.setVisible(false);
        txtFromDate.setVisible(true);
        txtToDate.setVisible(true);
        lblFrom.setVisible(true);
        lblTo.setVisible(true);
    }
}//GEN-LAST:event_cboSearchActionPerformed

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
// TODO add your handling code here:
    int select = cboSearch.getSelectedIndex();
    cboView.setSelectedIndex(0);
    try {
        switch (select) {
            case 0:
                loanContacts = blLoanContact.getByID(user, txtSearch.getText());
                break;
            case 1:
                loanContacts = blLoanContact.getByCustomerID(user, txtSearch.getText());
                break;
            case 2:
                loanContacts = blLoanContact.getByAmount(user, txtFromAmount.getText(), txtToAmount.getText());
                break;
            case 3:
                if (txtFromDate.isValid() || txtToDate.isValid()) {
                    JOptionPane.showMessageDialog(null, "From date and to date can not null.", "Error", JOptionPane.ERROR_MESSAGE);
                    loanContacts = null;
                } else {
                    java.sql.Date fdate = new java.sql.Date(txtFromDate.getDate().getTime());
                    java.sql.Date tdate = new java.sql.Date(txtToDate.getDate().getTime());
                    loanContacts = blLoanContact.getByDate(user, fdate, tdate);
                }
                break;

            default:
                break;
        }

        if (loanContacts.size() == 0) {
            JOptionPane.showMessageDialog(pnlControl, Localization.getMessage("NotFound"), "Information", JOptionPane.INFORMATION_MESSAGE);
        }
        loadModel(loanContacts);
    } catch (Exception e) {
    }

}//GEN-LAST:event_btnSearchActionPerformed

private void btnKeepTrackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnKeepTrackActionPerformed
// TODO add your handling code here:
    GUIKeeptrack keeptrack = new GUIKeeptrack(null, true, user, loanContact);
    keeptrack.setVisible(true);
}//GEN-LAST:event_btnKeepTrackActionPerformed

private void btnApprovedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnApprovedActionPerformed
// TODO add your handling code here:
    int select = JOptionPane.showConfirmDialog(pnlControl, "Are you sure you want to accept loan?" ,"Accept Loan",JOptionPane.OK_OPTION);
    if(select == 0 ){
        blLoanContact.accecpted(loanContact.getLoanId(), loanContact.getLoantype().getLoanTypeID(),user);
        refreshData();
    }
    
}//GEN-LAST:event_btnApprovedActionPerformed

private void tblListMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblListMousePressed
// TODO add your handling code here:
    int row = this.tblList.getSelectedRow();
    loanContact = loanContacts.get(row);

    lblCustomerID.setText(String.valueOf(loanContact.getCustomer().getCustomeId()));
    lblFullName.setText(String.valueOf(loanContact.getCustomer().getFullname()));
    lblAddress.setText(String.valueOf(loanContact.getCustomer().getAddress()));
    lblEmail.setText(String.valueOf(loanContact.getCustomer().getEmail()));
    lblGrossSalary.setText(String.valueOf(loanContact.getCustomer().getGrossSalary()));
    lblPhoneNumber.setText(String.valueOf(loanContact.getCustomer().getPhone()));
    lblOrgazination.setText(String.valueOf(loanContact.getCustomer().getOrganzination()));
    lblLoanID.setText(String.valueOf(loanContact.getLoanId()));
    cboLoanType.setSelectedItem(loanContact.getLoantype().getTypeOfLoan());
    txtAmount.setText(String.valueOf(loanContact.getAmount()));
    txtDate.setDate(loanContact.getDateStart());
    if (loanContact.isIsAccepted() == 2) {
        this.btnApproved.setEnabled(true);
        this.btnDeline.setEnabled(true);
        this.btnKeepTrack.setEnabled(false);
    }

    if (loanContact.isIsAccepted() == 1) {
        this.btnKeepTrack.setEnabled(true);
        this.btnApproved.setEnabled(false);
        this.btnDeline.setEnabled(false);
    }

    if (loanContact.isIsAccepted() == 0) {
        this.btnKeepTrack.setEnabled(false);
        this.btnApproved.setEnabled(true);
        this.btnDeline.setEnabled(false);
    }



}//GEN-LAST:event_tblListMousePressed

private void cboViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboViewActionPerformed
// TODO add your handling code here:
    int select = cboView.getSelectedIndex();
    if (select != 0) {
        try {
            loanContacts = blLoanContact.getLoanContactSelect(select, user);
            loadModel(loanContacts);
        } catch (Exception ex) {
        }
    }
}//GEN-LAST:event_cboViewActionPerformed

private void txtFromAmountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFromAmountActionPerformed
// TODO add your handling code here:
    txtFromAmount.setText("");
}//GEN-LAST:event_txtFromAmountActionPerformed

private void txtToAmountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtToAmountActionPerformed
// TODO add your handling code here:
    txtToAmount.setText("");
}//GEN-LAST:event_txtToAmountActionPerformed

private void btnDelineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelineActionPerformed
// TODO add your handling code here:
    int select = JOptionPane.showConfirmDialog(pnlControl, "Are you sure you want to deline loan?" ,"Deline Loan",JOptionPane.OK_OPTION);
    if(select == 0 ){
        blLoanContact.notAccecpted(loanContact.getLoanId(), user);
        refreshData();
    }
}//GEN-LAST:event_btnDelineActionPerformed

private void btnListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnListActionPerformed
    // TODO add your handling code here:
    refreshData();
}//GEN-LAST:event_btnListActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnApproved;
    private javax.swing.JButton btnDeline;
    private javax.swing.JButton btnKeepTrack;
    private javax.swing.JButton btnList;
    private javax.swing.JButton btnSearch;
    private javax.swing.JComboBox cboLoanType;
    private javax.swing.JComboBox cboSearch;
    private javax.swing.JComboBox cboView;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblAddress;
    private javax.swing.JLabel lblCustomerID;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblFrom;
    private javax.swing.JLabel lblFullName;
    private javax.swing.JLabel lblGrossSalary;
    private javax.swing.JLabel lblLoanID;
    private javax.swing.JLabel lblOrgazination;
    private javax.swing.JLabel lblPhoneNumber;
    private javax.swing.JLabel lblTo;
    private javax.swing.JPanel pnlBottom;
    private javax.swing.JPanel pnlControl;
    private javax.swing.JPanel pnlCustomerDetails;
    private javax.swing.JPanel pnlLoanDetails;
    private javax.swing.JPanel pnlTop;
    private javax.swing.JTable tblList;
    private javax.swing.JTextField txtAmount;
    private com.toedter.calendar.JDateChooser txtDate;
    private javax.swing.JTextField txtFromAmount;
    private com.toedter.calendar.JDateChooser txtFromDate;
    private javax.swing.JTextField txtSearch;
    private javax.swing.JTextField txtToAmount;
    private com.toedter.calendar.JDateChooser txtToDate;
    // End of variables declaration//GEN-END:variables
}
